<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     Pagizer
 * @subpackage  backoffice
 */

class m_backoffice_actions_block_DeleteFolderAction extends m_backoffice_extends_FormModal
{
	public function execute()
	{
        $folder = f_document_Provider::getInstance()->getByModelAndUniqueId('backoffice/Folder', $this->getRequestParameter("docId"), $this->getRequestParameter("docLang"));

        $fields = $folder->relationFields();

        $count = 0;
        if(is_array($fields) && count($fields) > 0)
        {
            foreach($fields as $field)
            {
                $count += f_relation_Manager::getInstance()->getChildsNb($folder, $field, $this->getRequestParameter("docLang"));
            }
        }

        $this->addToModel("hasChild", $count > 0);		
		$this->addToModel("folder", $folder);
		$this->setView('success');
	}	
		
	public function errorHandler()
	{
		return null;
	}
}